# -*- coding: utf-8 -*-
'''
Created on 2013-9-18

@author: johnw
'''
from openerp.osv import osv
from openerp import netsvc
class account_invoice(osv.osv):
    '''Override account invoice to force checking of purchase.order workflow in order to
    recheck conditions depending on invoiced'''
    _inherit = 'account.invoice'
    
    def invoice_validate(self, cr, uid, ids, context=None):
        res = super(account_invoice, self).invoice_validate(cr, uid, ids, context=context)
        purchase_order_obj = self.pool.get('purchase.order')
        po_ids = purchase_order_obj.search(cr, uid, [('invoice_ids', 'in', ids)], context=context)
        wf_service = netsvc.LocalService("workflow")
        for po_id in po_ids:
            wf_service.trg_write(uid, 'purchase.order', po_id, cr)
        return res
